<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
	<h1>Checkbox 勾选操作</h1>
	<h6>[ 文件路径: excheck/checkbox.html ]</h6>
	<div class="content_wrap">
		<div class="zTreeDemoBackground left">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
		<div class="right">
			<ul class="info">
				<li class="title"><h2>1、setting 配置信息说明</h2>
					<ul class="list">
						<li class="highlight_red">使用 checkbox，必须设置 setting.check
							中的各个属性，详细请参见 API 文档中的相关内容</li>
						<li><p>
								父子关联关系：<br /> 被勾选时：<input type="checkbox" id="py"
									class="checkbox first" checked /><span>关联父</span> <input
									type="checkbox" id="sy" class="checkbox first" checked /><span>关联子</span><br />
								取消勾选时：<input type="checkbox" id="pn" class="checkbox first"
									checked /><span>关联父</span> <input type="checkbox" id="sn"
									class="checkbox first" checked /><span>关联子</span><br />
							<ul id="code" class="log" style="height: 20px;"></ul>
							</p></li>
					</ul></li>
				<li class="title"><h2>2、treeNode 节点数据说明</h2>
					<ul class="list">
						<li class="highlight_red">1)、如果需要初始化默认节点被勾选，请设置
							treeNode.checked 属性，详细请参见 API 文档中的相关内容</li>
						<li class="highlight_red">2)、如果某节点禁用 checkbox，请设置
							treeNode.chkDisabled 属性，详细请参见 API 文档中的相关内容 和 'chkDisabled 演示'</li>
						<li class="highlight_red">3)、如果某节点不显示 checkbox，请设置
							treeNode.nocheck 属性，详细请参见 API 文档中的相关内容 和 'nocheck 演示'</li>
						<li class="highlight_red">4)、如果更换 checked 属性，请参考 API 文档中
							setting.data.key.checked 的详细说明</li>
						<li>5)、其他请参考 API 文档中 treeNode.checkedOld / getCheckStatus /
							check_Child_State / check_Focus 的详细说明</li>
					</ul></li>
			</ul>
		</div>
	</div>
</body>
<%@ include file="/common.jsp"%>
<SCRIPT type="text/javascript">
	var setting = {
		view : {
			selectedMulti : false
		},
		check : {
			enable : true
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeCheck : beforeCheck,
			onCheck : onCheck
		}
	};

	var zNodes = [ {
		id : 1,
		pId : 0,
		name : "随意勾选 1",
		open : true
	}, {
		id : 11,
		pId : 1,
		name : "随意勾选 1-1"
	}, {
		id : 12,
		pId : 1,
		name : "随意勾选 1-2",
		open : true
	}, {
		id : 121,
		pId : 12,
		name : "随意勾选 1-2-1"
	}, {
		id : 122,
		pId : 12,
		name : "随意勾选 1-2-2"
	}, {
		id : 2,
		pId : 0,
		name : "禁止勾选 2",
		open : true,
		doCheck : false
	}, {
		id : 21,
		pId : 2,
		name : "禁止勾选 2-1",
		doCheck : false
	}, {
		id : 22,
		pId : 2,
		name : "禁止勾选 2-2",
		checked : true,
		open : true,
		doCheck : false
	}, {
		id : 221,
		pId : 22,
		name : "禁止勾选 2-2-1",
		doCheck : false
	}, {
		id : 222,
		pId : 22,
		name : "禁止勾选 2-2-2",
		checked : true,
		doCheck : false
	}, {
		id : 23,
		pId : 2,
		name : "禁止勾选 2-3",
		doCheck : false
	} ];

	var code, log, className = "dark";
	function beforeCheck(treeId, treeNode) {
		className = (className === "dark" ? "" : "dark");
		showLog("[ " + getTime() + " beforeCheck ]&nbsp;&nbsp;&nbsp;&nbsp;"
				+ treeNode.name);
		return (treeNode.doCheck !== false);
	}
	function onCheck(e, treeId, treeNode) {
		showLog("[ " + getTime() + " onCheck ]&nbsp;&nbsp;&nbsp;&nbsp;"
				+ treeNode.name);
	}
	function showLog(str) {
		if (!log)
			log = $("#log");
		log.append("<li class='"+className+"'>" + str + "</li>");
		if (log.children("li").length > 6) {
			log.get(0).removeChild(log.children("li")[0]);
		}
	}
	function getTime() {
		var now = new Date(), h = now.getHours(), m = now.getMinutes(), s = now
				.getSeconds(), ms = now.getMilliseconds();
		return (h + ":" + m + ":" + s + " " + ms);
	}

	function checkNode(e) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo"), type = e.data.type, nodes = zTree
				.getSelectedNodes();
		if (type.indexOf("All") < 0 && nodes.length == 0) {
			alert("请先选择一个节点");
		}

		if (type == "checkAllTrue") {
			zTree.checkAllNodes(true);
		} else if (type == "checkAllFalse") {
			zTree.checkAllNodes(false);
		} else {
			var callbackFlag = $("#callbackTrigger").attr("checked");
			for ( var i = 0, l = nodes.length; i < l; i++) {
				if (type == "checkTrue") {
					zTree.checkNode(nodes[i], true, false, callbackFlag);
				} else if (type == "checkFalse") {
					zTree.checkNode(nodes[i], false, false, callbackFlag);
				} else if (type == "toggle") {
					zTree.checkNode(nodes[i], null, false, callbackFlag);
				} else if (type == "checkTruePS") {
					zTree.checkNode(nodes[i], true, true, callbackFlag);
				} else if (type == "checkFalsePS") {
					zTree.checkNode(nodes[i], false, true, callbackFlag);
				} else if (type == "togglePS") {
					zTree.checkNode(nodes[i], null, true, callbackFlag);
				}
			}
		}
	}

	function setAutoTrigger(e) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.setting.check.autoCheckTrigger = $("#autoCallbackTrigger").attr(
				"checked");
		$("#autoCheckTriggerValue").html(
				zTree.setting.check.autoCheckTrigger ? "true" : "false");
	}

	function tree_wdf() {
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		$("#checkTrue").bind("click", {
			type : "checkTrue"
		}, checkNode);
		$("#checkFalse").bind("click", {
			type : "checkFalse"
		}, checkNode);
		$("#toggle").bind("click", {
			type : "toggle"
		}, checkNode);
		$("#checkTruePS").bind("click", {
			type : "checkTruePS"
		}, checkNode);
		$("#checkFalsePS").bind("click", {
			type : "checkFalsePS"
		}, checkNode);
		$("#togglePS").bind("click", {
			type : "togglePS"
		}, checkNode);
		$("#checkAllTrue").bind("click", {
			type : "checkAllTrue"
		}, checkNode);
		$("#checkAllFalse").bind("click", {
			type : "checkAllFalse"
		}, checkNode);

		$("#autoCallbackTrigger").bind("change", {}, setAutoTrigger);
	};
	$.ajax({
		url : '${pageContext.request.contextPath}/ykfk/bb.do',
		type : "post",
		dataType : "json",
		timeout : 1000000,
		error : function() {
		},
		success : function(data) {
			zNodes = data;
			tree_wdf();
// 			for ( var i = 0; i < data.length; i++) {
// 				alert(data[i].modCode);
// 				zNodes = data;
// 			}
		}
	});
</SCRIPT>
</html>